﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Leadtools;
using Leadtools.Codecs;
using System.Collections;

namespace MINERP.DigitalOutput.MyControls
{
    public partial class UserPrinter : UserControl
    {
        public UserPrinter()
        {
            InitializeComponent();
        }

        public event MouseEventHandler user_MouseClick;
        public event DragEventHandler user_DragEnter;
        public event DragEventHandler user_DragDrop;
        //public event EventHandler user_DragLeave;

        //属性
        private int _printerID;
        public int PrinterID
        {
            get { return _printerID; }
            set { _printerID = value; }
        }
        private int _printerDPI;
        public int PrinterDPI
        {
            get { return _printerDPI; }
            set { _printerDPI = value; }
        }

        private void UserPrinter_Load(object sender, EventArgs e)
        {
            //设置点击事件
            SetClick(splitContainer1);
            SetThumb();

        }
        private void SetClick(Control c)
        {
            c.AllowDrop = true;
            c.MouseClick += new MouseEventHandler(rasterImageViewer1_MouseClick);
            c.MouseEnter += new EventHandler(rasterImageViewer1_MouseEnter);
            c.MouseLeave += new EventHandler(rasterImageViewer1_MouseLeave);
            c.DragEnter += new DragEventHandler(rasterImageViewer1_DragEnter);
            c.DragDrop += new DragEventHandler(rasterImageViewer1_DragDrop);
            c.DragLeave += new EventHandler(rasterImageViewer1_DragLeave);
            ControlCollection cs = c.Controls;
            if (cs != null && cs.Count > 0)
            {
                foreach (Control subC in cs)
                {
                    SetClick(subC);
                }
            }
        }
        //设置打印机的基本信息
        public void SetBaseInfo(string printerName, string printerType, int printerDPI)
        {
            lblPrinterName.Text = printerName;
            lblPrinterType.Text = printerType;
            lblDPI.Text = printerDPI.ToString();
            PrinterDPI = printerDPI;
        }
        //设置打印机待打印的照片数量
        public void SetTaskNum(int num)
        {
            int srcTaskNum = Convert.ToInt32(lblTaskNum.Text);
            lblTaskNum.Text = ((int)(srcTaskNum + num)).ToString();
        }
        //设置打印机的默认缩略图
        private void SetThumb()
        {
            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                CodecsThumbnailOptions options = new CodecsThumbnailOptions();
                options.LoadStamp = true;
                options.Resample = true;
                options.MaintainAspectRatio = true;
                Image imgg = Properties.Resources.打印管理;
                //Image imgg=Image.FromFile(Application.StartupPath+(@"\imgs\打印管理.png"));
                RasterImage img = new RasterImage(imgg);
                //RasterImage img = codecs.ReadThumbnail(@"imgs\DisplayPrinter.jpg", options, 1);
                rasterImageViewer1.Image = img;
                rasterImageViewer1.AutoScroll = false;
                codecs.Dispose();
                RasterCodecs.Shutdown();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //鼠标移过图片时,变化边框,突出显示
        private void rasterImageViewer1_MouseMove(object sender, MouseEventArgs e)
        {
            //rasterImageViewer1.BorderStyle = BorderStyle.Fixed3D;
            //panel1.BorderStyle = BorderStyle.Fixed3D;
        }
        //鼠标移出图片时,去除边框
        private void rasterImageViewer1_MouseLeave(object sender, EventArgs e)
        {
                panel1.BorderStyle = BorderStyle.FixedSingle;
        }

        #region 点击分配照片
        //鼠标点击时分配照片
        private void rasterImageViewer1_MouseClick(object sender, MouseEventArgs e)
        {
            if (user_MouseClick != null)
            {
                this.user_MouseClick(sender, e);
            }
        }
        #endregion

        public void SetBackColor()
        {
            int taskNum = Convert.ToInt32(lblTaskNum.Text);
            if (taskNum <= 5)
            {
                splitContainer1.BackColor = Control.DefaultBackColor;
            }
            else if (taskNum <= 10)
                splitContainer1.BackColor = Color.MistyRose;
            else if (taskNum <= 20)
                splitContainer1.BackColor = Color.Salmon;

        }

        private void rasterImageViewer1_MouseEnter(object sender, EventArgs e)
        {
            panel1.BorderStyle = BorderStyle.Fixed3D;
        }

        #region 接收拖曳操作
        //接收拖曳操作
        private void rasterImageViewer1_DragEnter(object sender, DragEventArgs e)
        {
            panel1.BorderStyle = BorderStyle.Fixed3D;
            if (user_DragEnter != null)
                user_DragEnter(sender, e);
        }

        private void rasterImageViewer1_DragDrop(object sender, DragEventArgs e)
        {
            if (user_DragDrop != null)
                user_DragDrop(sender, e);
        }

        private void rasterImageViewer1_DragLeave(object sender, EventArgs e)
        {
            if (sender is Panel)
                panel1.BorderStyle = BorderStyle.FixedSingle;
        }
        #endregion

    }
}
